package com.lzx.lizhenxing.delivery.service.impl;

import com.github.pagehelper.PageHelper;
import com.lzx.lizhenxing.common.utils.UserUtils;
import com.lzx.lizhenxing.common.vo.PageVo;
import com.lzx.lizhenxing.delivery.dao.DeliveryPersonTaskDao;
import com.lzx.lizhenxing.delivery.param.DeliveryTaskPageParam;
import com.lzx.lizhenxing.delivery.service.DeliveryPersonTaskService;
import com.lzx.lizhenxing.delivery.vo.DeliveryTaskVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class DeliveryPersonTaskServiceImpl implements DeliveryPersonTaskService {
    @Resource
    private DeliveryPersonTaskDao deliverPersonTaskDao;

    @Override
    public PageVo<DeliveryTaskVo> getDeliveryTask(DeliveryTaskPageParam param) {
        Long uid = UserUtils.getUser();
        // 这里只是为了给数据库查询sql设置limit条件
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        // mapper层写连表查询sql获取对应的数据
        // 注意sql中需要根据配送时间升序
        List<DeliveryTaskVo> list = deliverPersonTaskDao.selectTaskPage(uid, param.getRecipient(), param.getRecipientPhone());

        PageVo<DeliveryTaskVo> pageVo = new PageVo<>();
        pageVo.setDataList(list);
        pageVo.setTotal(list.size());
        return pageVo;
    }
}
